﻿using Taype.Trading.BTC.MtGoxAPIClient.JSONObjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using BitCoinSharp;

namespace MtGoxAPIClient_test
{
    
    
    /// <summary>
    ///This is b test class for MtGoxBTCAddressTest and is intended
    ///to contain all MtGoxBTCAddressTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MtGoxBTCAddressTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in b class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for MtGoxBTCAddress Constructor
        ///</summary>
        [TestMethod()]
        public void MtGoxBTCAddressConstructorTest()
        {
            MtGoxBTCAddress target = new MtGoxBTCAddress();
            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for getObjects
        ///</summary>
        [TestMethod()]
        public void getObjectsMtGoxBTCAddressTest()
        {
            // here is a valid bticoin address: 19PfYA5SdL9BRayLcLPgNNYwGXwypV3rYB
            // jsonDataStr will look like: "{\"addr\":\"1QKvSbJBo22GtPZYthswjrDcH7weRjMaVi\"}"
            // Here is a real BTC address: 1JaFaFSfpVT4xbYeSAjCXZmd9FLrWe3Hnz and the associated Hash160
            // Hash160	{byte[20]}	byte[]
            //[0]	192	byte
            //[1]	196	byte
            //[2]	7	byte
            //[3]	187	byte
            //[4]	166	byte
            //[5]	146	byte
            //[6]	142	byte
            //[7]	33	byte
            //[8]	55	byte
            //[9]	228	byte
            //[10]	50	byte
            //[11]	212	byte
            //[12]	71	byte
            //[13]	10	byte
            //[14]	187	byte
            //[15]	152	byte
            //[16]	226	byte
            //[17]	189	byte
            //[18]	253	byte
            //[19]	237	byte
            // 
            string jsonDataStr = "{\"addr\":\"1JaFaFSfpVT4xbYeSAjCXZmd9FLrWe3Hnz\"}";
            byte[] h160 = new byte[] { 192, 196, 7, 187, 166, 146, 142, 33, 55, 228, 50, 212, 71, 10, 187, 152, 226, 189, 253, 237 };
            Address expected = new Address(new NetworkParameters(), h160);
            Address actual;
            actual = MtGoxBTCAddress.getObjects(jsonDataStr);
            Assert.AreEqual(expected, actual);
        }
    }
}
